home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-13 | 3.7 KB | 174 lines | [TEXT/CWIE] |
- /*
- File: PickerCommonDraw.c
- Copyright: © 1996-1997 by Apple Computer, Inc., all rights reserved.
- */
-
-
- //===============================================================================
- //
- // PickerCommonDraw.c
- //
- //===============================================================================
-
-
- #include <Memory.h> // <-- System interfaces.
- #include <ColorPicker.h>
- #include "PickerCommon.h" // <-- Project interfaces.
-
-
- static void DarkenColor ( RGBColor *color );
-
-
- //===================================================================== Functions
- //--------------------------------------------------------------------- DropRectShadow
-
- void DropRectShadow (Rect *theRect, SInt16 dropDist, Boolean useColor)
- {
- RGBColor grayColor;
- Rect dropShadow;
- RgnHandle wasClip, newClip;
- SInt16 i;
-
- BackColor(whiteColor);
-
- wasClip = NewRgn();
- if (!wasClip)
- return;
- GetClip(wasClip);
-
- newClip = NewRgn();
- if (!newClip)
- return;
- InsetRect(theRect, 1, 1);
- RectRgn(newClip, theRect);
- InsetRect(theRect, -1, -1);
- DiffRgn(wasClip, newClip, newClip);
- SetClip(newClip);
-
- dropShadow = *theRect;
- OffsetRect(&dropShadow, dropDist, dropDist);
-
- if (useColor)
- {
- grayColor.red = 0x8000;
- grayColor.green = 0x8000;
- grayColor.blue = 0x8000;
- OpColor(&grayColor);
- PenMode(blend);
-
- grayColor.red = 0xE000;
- grayColor.green = 0xE000;
- grayColor.blue = 0xE000;
-
- for (i = 0; i < 4; i++)
- {
- RGBForeColor(&grayColor);
- InsetRect(&dropShadow, 1, 1);
- PaintRoundRect(&dropShadow, 6, 6);
- DarkenColor( &grayColor );
- }
-
- ForeColor(blackColor);
- PenMode(srcCopy);
- }
- else
- {
- Pattern blackPattern;
- Pattern grayPattern;
- StuffHex(&blackPattern,"\pFFFFFFFFFFFFFFFF");
- StuffHex(&grayPattern, "\p2288228822882288");
- PenPat(&grayPattern);
- InsetRect(&dropShadow, 1, 1);
- PaintRect(&dropShadow);
- PenPat(&blackPattern);
- }
-
- SetClip(wasClip);
- DisposeRgn(wasClip);
- DisposeRgn(newClip);
- }
-
- //-------------------------------------------------------------------- CreateOffScreenGWorld
- // Dims the color passed in towards black.
-
- static void DarkenColor( RGBColor *color )
- {
- #define kGrayStep 0x0C00
-
- if (color->red >= kGrayStep)
- color->red -= kGrayStep;
- else
- color->red = 0x0000;
-
- if (color->green >= kGrayStep)
- color->green -= kGrayStep;
- else
- color->green = 0x0000;
-
- if (color->blue >= kGrayStep)
- color->blue -= kGrayStep;
- else
- color->blue = 0x0000;
- }
-
- //--------------------------------------------------------------------- SetPatternToColor
- // Set the pattern pat to best represent the color rgb.
- // If we're on a color machine, use MakeRGBPat,
- // otherwise pat is really a Pattern **, so set it the best B&W pattern.
-
- void SetPatternToColor (PixPatHandle pat, RGBColor *rgb, Boolean hasColor)
- {
- if (!pat)
- return;
-
- if (hasColor)
- {
- MakeRGBPat(pat, rgb);
- check(QDError() == noErr);
- }
- else
- {
- HSLColor hsl;
- Pattern tempPat;
-
- RGB2HSL(rgb, &hsl);
- GetGrayPattern(hsl.lightness, &tempPat);
-
- HLock((Handle)pat);
- BlockMoveData(&tempPat, *pat, 8);
- HUnlock((Handle)pat);
- }
- }
-
- //--------------------------------------------------------------------- GetGrayPattern
- // Find a B&W pattern that best matches lightness (0 == black,
- // 65535 == white) and store it in "pat".
-
- void GetGrayPattern (unsigned short lightness, Pattern *pat)
- {
- short index;
-
- index = (lightness / 8192);
- switch (index)
- {
- case 0: // 0-8192
- case 1: // 8192-16383
- case 2: // 16384-24576
- case 3: // 24576-32767
- GetIndPattern(pat, sysPatListID, index + 1);
- break;
-
- case 4: // 32768-40959
- case 5: // 40960-49151
- case 6: // 49152-57343
- case 7: // 57344-65535
- GetIndPattern(pat, sysPatListID, 27 - index);
- break;
-
- default:
- check(true);
- break;
- }
- }
-
-